//
//  TopUpAndWithdrawView.m
//  PigMarket
//
//  Created by mac on 2019/5/28.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "TopUpAndWithdrawView.h"

@interface TopUpAndWithdrawView ()
/**
 输入框view
 */
@property (nonatomic , strong) UIView *inputView;
/**
 ￥
 */
@property (nonatomic , strong) UILabel *moneyIconLab;
/**
 line
 */
@property (nonatomic , strong) UIView *line;

/**
 wechatView
 */
@property (nonatomic , strong) UIView *wechatView;
/**
 alipayView
 */
@property (nonatomic , strong) UIView *alipayView;
/**
 type
 */
@property (nonatomic , strong) NSString *type;
@end
@implementation TopUpAndWithdrawView
#pragma mark - init method
- (instancetype)initWithType:(NSString *)type
{
    self = [super init];
    if (self) {
        self.type = type;
        [self initView];
        [self initLayout];
        [self initData];
        [self initAction];
    }
    return self;
}

- (void)initView {
    // 添加子控件
    [self addSubview:self.inputView];
    [self.inputView addSubview:self.title];
    [self.inputView addSubview:self.moneyIconLab];
    [self.inputView addSubview:self.moneyInputField];
    [self.inputView addSubview:self.inputLine];
    [self.inputView addSubview:self.withdrawMoney];
    [self addSubview:self.payTypeTitle];
    
    [self addSubview:self.wechatView];
    [self.wechatView addSubview:self.wechatIcon];
    [self.wechatView addSubview:self.wechatTitleLab];
    [self.wechatView addSubview:self.wechatAccount];
    [self.wechatView addSubview:self.wechatSelectImg];
    [self.wechatView addSubview:self.line];
    
    [self addSubview:self.alipayView];
    [self.alipayView addSubview:self.alipayIcon];
    [self.alipayView addSubview:self.alipayTitleLab];
    [self.alipayView addSubview:self.alipayAccount];
    [self.alipayView addSubview:self.alipaySelectImg];

    [self addSubview:self.confirmBtn];
    
}

- (void)initLayout {
    // 布局子控件
    [self.inputView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(10);
    }];
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(10);
        make.height.mas_equalTo(20);
    }];
    [self.moneyIconLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.title.mas_left);
        make.top.mas_equalTo(self.title.mas_bottom).offset(18);
        make.height.mas_equalTo(36);
        make.width.mas_equalTo(20);
    }];
    [self.moneyInputField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.moneyIconLab.mas_right).offset(5);
        make.centerY.mas_equalTo(self.moneyIconLab.mas_centerY);
        make.height.mas_equalTo(52);
        make.right.mas_equalTo(-15);
    }];

    [self.inputLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(self.moneyInputField.mas_bottom).offset(7);
        make.height.mas_equalTo(1);
    }];
    [self.withdrawMoney mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.title.mas_left);
        make.top.mas_equalTo(self.inputLine.mas_bottom).offset(10);
        make.height.mas_equalTo(20);
        make.bottom.mas_equalTo(-10);
    }];
    
    
    [self.payTypeTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(self.inputView.mas_bottom).offset(20);
        make.height.mas_equalTo(20);
    }];
    
    [self.wechatView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(self.payTypeTitle.mas_bottom).offset(10);
        make.height.mas_equalTo(64);
    }];
    [self.wechatIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.title.mas_left);
        make.top.mas_equalTo(10);
        make.size.mas_equalTo(CGSizeMake(44, 44));
    }];
    [self.wechatTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.wechatIcon.mas_right).offset(20);
        make.top.mas_equalTo(12);
        make.height.mas_equalTo(18);
    }];
    [self.wechatAccount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.wechatIcon.mas_left);
        make.top.mas_equalTo(self.wechatIcon.mas_bottom).offset(6);
        make.height.mas_equalTo(16);
    }];
    [self.wechatSelectImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.centerY.mas_equalTo(self.wechatView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(18, 18));
    }];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(1);
        make.bottom.mas_equalTo(0);
    }];
    [self.alipayView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(self.wechatView.mas_bottom);
        make.height.mas_equalTo(64);
    }];
    [self.alipayIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.title.mas_left);
        make.top.mas_equalTo(10);
        make.size.mas_equalTo(CGSizeMake(44, 44));
    }];
    [self.alipayTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.alipayIcon.mas_right).offset(20);
        make.top.mas_equalTo(12);
        make.height.mas_equalTo(18);
    }];
    [self.alipayAccount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.alipayIcon.mas_left);
        make.top.mas_equalTo(self.alipayTitleLab.mas_bottom).offset(6);
        make.height.mas_equalTo(16);
    }];
    [self.alipaySelectImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.centerY.mas_equalTo(self.alipayView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(18, 18));
    }];
    [self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30);
        make.bottom.mas_equalTo(-60 * [JTool getScreenWidthScale]);
        make.right.mas_equalTo(-30);
        make.height.mas_equalTo(48 * [JTool getScreenWidthScale]);
    }];
}
- (void)initData {
    
    if ([self.type rangeOfString:@"充值"].location != NSNotFound) {
        self.inputLine.hidden = YES;
        self.withdrawMoney.hidden = YES;
        [self.moneyInputField mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(-8);
        }];
    }

}
#pragma mark - initAction
- (void)initAction {
     UITapGestureRecognizer *wechatTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(wechatTapped)];
    [self.wechatView addGestureRecognizer:wechatTap];
   
    UITapGestureRecognizer *alipayTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(alipayTapped)];
    [self.alipayView addGestureRecognizer:alipayTap];
}
- (void)wechatTapped {
    
    if (self.wechatBlock) {
        self.wechatBlock();
    }
}
- (void)alipayTapped {
    if (self.alipayBlock) {
        self.alipayBlock();
    }
}
#pragma mark - getter and setter
- (UIView *)inputView {
    if (!_inputView) {
        _inputView = [[UIView alloc] init];
        _inputView.backgroundColor = [UIColor whiteColor];
    }
    return _inputView;
}
- (UIView *)wechatView {
    if (!_wechatView) {
        _wechatView = [[UIView alloc] init];
        _wechatView.backgroundColor = [UIColor whiteColor];
    }
    return _wechatView;
}
- (UIView *)alipayView {
    if (!_alipayView) {
        _alipayView = [[UIView alloc] init];
        _alipayView.backgroundColor = [UIColor whiteColor];
    }
    return _alipayView;
}
- (UILabel *)title {
    if (!_title) {
        _title = [[UILabel alloc] init];
        _title.textColor = [UIColor textBlackColor];
        _title.font = [UIFont middleFont];
    }
    return _title;
}
- (UILabel *)moneyIconLab {
    if (!_moneyIconLab) {
        _moneyIconLab = [[UILabel alloc] init];
        _moneyIconLab.textColor = [UIColor colorWithHexString:@"#333333"];
        _moneyIconLab.font = [UIFont systemFontOfSize:25];
        _moneyIconLab.text = @"￥";
    }
    return _moneyIconLab;
}
- (UITextField *)moneyInputField {
    if (!_moneyInputField) {
        _moneyInputField = [[UITextField alloc] init];
        _moneyInputField.keyboardType = UIKeyboardTypeDecimalPad;
        _moneyInputField.font = [UIFont systemFontOfSize:37];
        [_moneyInputField setValue:[UIColor colorWithHexString:@"#808080"] forKeyPath:@"_placeholderLabel.textColor"];
        _moneyInputField.placeholder = @"0.00";
    }
    return _moneyInputField;
}

- (UIView *)inputLine {
    if (!_inputLine) {
        _inputLine = [[UIView alloc] init];
        _inputLine.backgroundColor = [UIColor colorWithHexString:@"#F7F7F7"];
    }
    return _inputLine;
}
- (UILabel *)withdrawMoney {
    if (!_withdrawMoney) {
        _withdrawMoney = [[UILabel alloc] init];
        _withdrawMoney.textColor = [UIColor colorWithHexString:@"#808080"];
        _withdrawMoney.font = [UIFont systemFontOfSize:13];
    }
    return _withdrawMoney;
}
- (UILabel *)payTypeTitle {
    if (!_payTypeTitle) {
        _payTypeTitle = [[UILabel alloc] init];
        _payTypeTitle.textColor = [UIColor colorWithHexString:@"#808080"];
        _payTypeTitle.font = [UIFont systemFontOfSize:13];
    }
    return _payTypeTitle;
}
- (UIImageView *)wechatIcon {
    if (!_wechatIcon) {
        _wechatIcon = [[UIImageView alloc] init];
        _wechatIcon.image = [UIImage imageNamed:@"user_myasset_wechat"];
    }
    return _wechatIcon;
}
- (UILabel *)wechatTitleLab {
    if (!_wechatTitleLab) {
        _wechatTitleLab = [[UILabel alloc] init];
        _wechatTitleLab.textColor = [UIColor colorWithHexString:@"#444444"];
        _wechatTitleLab.font = [UIFont systemFontOfSize:13];
        _wechatTitleLab.text = @"微信";
    }
    return _wechatTitleLab;
}
- (UILabel *)wechatAccount {
    if (!_wechatAccount) {
        _wechatAccount = [[UILabel alloc] init];
        _wechatAccount.textColor = [UIColor colorWithHexString:@"#9C9FA1"];
        _wechatAccount.font = [UIFont systemFontOfSize:11];
        _wechatAccount.text = @"123";
    }
    return _wechatAccount;
}
- (UIView *)line {
    if (!_line) {
        _line = [[UIView alloc] init];
        _line.backgroundColor = [UIColor colorWithHexString:@"#F7F7F7"];
    }
    return _line;
}
- (UIImageView *)alipayIcon {
    if (!_alipayIcon) {
        _alipayIcon = [[UIImageView alloc] init];
        _alipayIcon.image = [UIImage imageNamed:@"user_myasset_alipay"];
    }
    return _alipayIcon;
}
- (UILabel *)alipayTitleLab {
    if (!_alipayTitleLab) {
        _alipayTitleLab = [[UILabel alloc] init];
        _alipayTitleLab.textColor = [UIColor colorWithHexString:@"#444444"];
        _alipayTitleLab.font = [UIFont systemFontOfSize:13];
        _alipayTitleLab.text = @"支付宝";
    }
    return _alipayTitleLab;
}
- (UILabel *)alipayAccount {
    if (!_alipayAccount) {
        _alipayAccount = [[UILabel alloc] init];
        _alipayAccount.textColor = [UIColor colorWithHexString:@"#9C9FA1"];
        _alipayAccount.font = [UIFont systemFontOfSize:11];
    }
    return _alipayAccount;
}
- (UIButton *)confirmBtn {
    if (!_confirmBtn) {
        _confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_confirmBtn setBackgroundImage:[UIImage imageNamed:@"btn_nomal_bg"] forState:UIControlStateNormal];
    }
    return _confirmBtn;
}
- (UIImageView *)wechatSelectImg {
    if (!_wechatSelectImg) {
        _wechatSelectImg = [[UIImageView alloc] init];
        _wechatSelectImg.image = [UIImage imageNamed:@"meat_cart_unchecked"];
    }
    return _wechatSelectImg;
}
- (UIImageView *)alipaySelectImg {
    if (!_alipaySelectImg) {
        _alipaySelectImg = [[UIImageView alloc] init];
        _alipaySelectImg.image = [UIImage imageNamed:@"meat_cart_unchecked"];
    }
    return _alipaySelectImg;
}
@end
